package com.scau.beyondboy;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * Author:beyondboy
 * Gmail:xuguoli.scau@gmail.com
 * Date: 2016/2/22
 * Time: 22:12
 * 全局类型转换器
 */
public class DateConvert implements Converter<String, Date>
{
    @Override
    public Date convert(String text)
    {
        Date date = null;
        try
        {
            if (text.contains("-"))
            {
                SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
                date = sf.parse(text);
                System.out.println("ConvertDate:"+date);
            } else
            {
                SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
                date = sf.parse(text);
            }

        } catch (ParseException e)
        {
            e.printStackTrace();
        }
        return date;
    }

}